package com.ry.demo.concurrent.demo;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: lihui
 * @Date: 2021-12-05 12:10
 * @Description:
 */
public class AtomicIntegerDemo {

    static class IntegerClass {

        static Integer count = 0;

        public static void main(String[] args) {
            for (int i = 0; i < 10; i++) {
                new Thread(()->{
                    synchronized(IntegerClass.class){
                        System.out.println(++IntegerClass.count);
                    }
                }).start();
            }

        }
    }

    static class AtomicIntegerClass {

        static AtomicInteger count = new AtomicInteger(0);

        public static void main(String[] args) {
            for (int i = 0; i < 10; i++) {
                new Thread(()->{
                    System.out.println(AtomicIntegerClass.count.incrementAndGet());
                }).start();
            }

        }
    }

}
